package com.mall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mall.db.domain.SendMessage;
import com.mall.db.service.SendMessageService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/system/smc")
public class SendMessageController extends BaseController<SendMessage> {
    @Resource(name = "sendMessageService")
    private SendMessageService sms;

    @Override
    public Map<String, Object> find(SendMessage sm) {
        PageHelper.startPage(sm.getPage(),sm.getLimit());
        QueryWrapper<SendMessage>qw=new QueryWrapper<>();
        List<SendMessage>list=sms.list(qw);
        PageInfo<SendMessage>pageInfo=new PageInfo<>(list,sm.getLimit());
        return super.findMap(pageInfo.getList(),pageInfo.getTotal());
    }

    @Override
    public Map<String, Object> add(SendMessage sm) {
        if (!StringUtils.isEmpty(sm.getAcceptType())&&"all".equals(sm.getAcceptType())){
            sm.setAcceptUser(null);
        }
        boolean b=sms.BatchSave(sm);
        return this.iud("信息发送",b,sm);
    }
}


